"-----------------------------------------------
" _____ ____   __     _____ __  __ ____   ____ "
"|  ___|  _ \  \ \   / /_ _|  \/  |  _ \ / ___|"
"| |_  | | | |  \ \ / / | || |\/| | |_) | |    "
"|  _| | |_| |  _\ V /  | || |  | |  _ <| |___ "
"|_|   |____/  (_)\_/  |___|_|  |_|_| \_\\____|"
"                                              "
"-----------------------------------------------
set number                     " 设置行号
set relativenumber             " 相对行号
set cmdheight=1
syntax on

set listchars=tab:»■,trail:■
set list                       " 显示空格和tab键

let mapleader=';'              " leader
nnoremap , ;

set encoding=utf-8
set fileencodings=utf-8,gb2312

set tabstop=2                  " 缩进长度
set shiftwidth=2
set expandtab                  " 设置tab为空格

set cursorline                 " 当前行高亮
set scrolloff=5                " 确保五行视野
set scroll=10                  " 设置<C-u/d>一次滚动距离

set termguicolors              " 色彩鲜艳

"set fdm=indent
set fdm=marker

"快速移动
nnoremap J 3j
nnoremap K 3k
nnoremap W 3w
nnoremap B 3b
nnoremap E 3e
vnoremap J 3j
vnoremap K 3k
vnoremap W 3w
vnoremap B 3b
vnoremap E 3e
" Copy to system clipboard
vnoremap Y "+y
nnoremap <silent><leader><leader>p "+p
nnoremap <silent><leader><leader>P "+P

"--------------------------------------------------------
"      _  __          _                         _       "
"     | |/ /___ _   _| |__   ___   __ _ _ __ __| |      "
"     | ' // _ \ | | | '_ \ / _ \ / _` | '__/ _` |      "
"     | . \  __/ |_| | |_) | (_) | (_| | | | (_| |      "
"     |_|\_\___|\__, |_.__/ \___/ \__,_|_|  \__,_|      "
"               |___/                                   "
"--------------------------------------------------------
"global keyboard
"正则表达式精确寻找
nnoremap <leader><leader>/  /\<\><left><left>
"全局快速精确替换
nnoremap <leader>cg :% s /\<\>/<left><left><left>
"代替esc
inoremap <leader>j <Esc>
vnoremap <leader>j <Esc>
"宏命令
nnoremap <leader><leader>q @q
"保存退出快捷键
nnoremap <leader>q :q<CR>
nnoremap <leader>w :w<CR>
"方向键位替补
inoremap <C-f> <Right>
inoremap <C-b> <Left>
"窗口切换
nnoremap <C-b> <C-W><C-W>
"分屏
nnoremap <leader>vs :vs<CR>
nnoremap <leader>sp :sp<CR>

nnoremap <leader>dy : r !figlet 

set background=dark
colorscheme gruvbox

"在一行内选择
nnoremap vil $v0
nnoremap vie v$h
nnoremap vis v0

" files keyboard
source ~/.config/nvim/snippits.vim

"buffer
nnoremap <leader>bd :bd<CR>
nnoremap <leader>bn :bn<CR>

"--------------------------------------------------------
"    __     _____ __  __   ____  _    _   _  ____       "
"    \ \   / /_ _|  \/  | |  _ \| |  | | | |/ ___|      "
"     \ \ / / | || |\/| | | |_) | |  | | | | |  _       "
"      \ V /  | || |  | | |  __/| |__| |_| | |_| |      "
"       \_/  |___|_|  |_| |_|   |_____\___/ \____|      "
"                                                       "
"--------------------------------------------------------
call plug#begin('~/.config/nvim/plugged')

"更改vim进入的初始样式
Plug 'mhinz/vim-startify'

"补全
Plug 'neoclide/coc.nvim', {'branch': 'release'}

"语法高亮
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}

"状态栏
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'

"更改括号
Plug 'tpope/vim-surround'

"快速注释
Plug 'tpope/vim-commentary'

"markdown-preview
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && yarn install'  }

"跳转
Plug 'easymotion/vim-easymotion'
Plug 'preservim/tagbar'

"缩进线
Plug 'Yggdroot/indentLine'

"多光标
Plug 'mg979/vim-visual-multi', {'branch': 'master'}

"对齐
Plug 'godlygeek/tabular'

"彩色括号
Plug 'luochen1990/rainbow'

"书签
Plug 'MattesGroeger/vim-bookmarks'

".命令
Plug 'tpope/vim-repeat'

"括号
Plug 'jiangmiao/auto-pairs'

"翻译
Plug 'voldikss/vim-translator'

"文件跳转
Plug 'preservim/nerdtree'
call plug#end()
"--------------------------------------------------------
"--------------------------------------------------------
"nerdtree
nnoremap <leader><leader>e :NERDTreeToggle<CR>
nnoremap <leader>er :NERDTreeFind<CR>
"translator
"let g:translator_proxy_url = 'socks5://127.0.0.1:7890'
nmap <Leader>pp :TranslateW<CR>
vmap <Leader>pp :TranslateW<CR>
nmap <Leader>eo :Translate<CR>
vmap <Leader>eo :Translate<CR>
"Tabularize
nnoremap <leader>tu : Tabu /
vnoremap <leader>tu : Tabu /

"Tagbar
nnoremap <silent> <leader>tt :TagbarToggle<CR>

"彩色括号rainbow
let g:rainbow_active = 1

"airline
let g:airline_theme='tomorrow'
let g:airline_left_sep = '▶ '
let g:airline_left_alt_sep = '❯'
let g:airline_right_sep = '◀'
let g:airline_right_alt_sep = '❮'
"function! AccentDemo()
"  let keys = ['M','Y',' ','C','O','D','E',' ']
"  for k in keys
"    call airline#parts#define_text(k, k)
"  endfor
"  call airline#parts#define_accent('a', 'red')
"  call airline#parts#define_accent('b', 'green')
"  call airline#parts#define_accent('c', 'blue')
"  call airline#parts#define_accent('d', 'yellow')
"  call airline#parts#define_accent('e', 'orange')
"  call airline#parts#define_accent('f', 'purple')
"  call airline#parts#define_accent('g', 'bold')
"  call airline#parts#define_accent('h', 'italic')
"  let g:airline_section_a = airline#section#create(keys)
"endfunction
"autocmd VimEnter * call AccentDemo()

"跳转easymotion
nmap <leader>ss <Plug>(easymotion-s2)

"markdown-preview
nmap <leader>mo <Plug>MarkdownPreview
nmap <leader>ms <Plug>MarkdownPreviewStop
nmap <leader>mt <Plug>MarkdownPreviewToggle
"let g:mkdp_auto_start = 1
"--------------------------------------------------------
"      ____ ___   ____   _   ___     _____ __  __       "
"     / ___/ _ \ / ___| | \ | \ \   / /_ _|  \/  |      "
"    | |  | | | | |     |  \| |\ \ / / | || |\/| |      "
"    | |__| |_| | |___  | |\  | \ V /  | || |  | |      "
"     \____\___/ \____| |_| \_|  \_/  |___|_|  |_|      "
"                                                       "
"--------------------------------------------------------
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
"inoremap <silent><expr> <TAB>
"            \ pumvisible() ? "\<C-n>" :
"            \ <SID>check_back_space() ? "\<TAB>" :
"选择无回车的一行
"            \ coc#refresh()
"inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
"
"function! s:check_back_space() abort
"    let col = col('.') - 1
"    return !col || getline('.')[col - 1]  =~# '\s'
"endfunction

" Use `[g` and `]g` to navigate diagnostics跳转到错误
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
"nmap <silent> gi <Plug>(coc-implementation)
"nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window.
nnoremap <silent> <leader>K :call <SID>show_documentation()<CR>

function! s:show_documentation()
    if (index(['vim','help'], &filetype) >= 0)
        execute 'h '.expand('<cword>')
    elseif (coc#rpc#ready())
        call CocActionAsync('doHover')
    else
        execute '!' . &keywordprg . " " . expand('<cword>')
    endif
endfunction
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c

"CocList
nnoremap <silent> <leader>li :CocList<CR>
nnoremap <silent> <leader>ln :CocList --normal<CR>

"CocCommand
nnoremap <silent> <leader>cm :CocCommand<CR>

"--------------------------------------------------------
"        ____ ___   ____   ____  _    _   _  ____       "
"       / ___/ _ \ / ___| |  _ \| |  | | | |/ ___|      "
"      | |  | | | | |     | |_) | |  | | | | |  _       "
"      | |__| |_| | |___  |  __/| |__| |_| | |_| |      "
"       \____\___/ \____| |_|   |_____\___/ \____|      "
"                                                       "
"--------------------------------------------------------
let g:coc_global_extensions = [
            \ 'coc-yank',
            \ 'coc-marketplace',
            \ 'coc-snippets',
            \ 'coc-lists',
            \ 'coc-go',
            \ 'coc-clangd',
            \ 'coc-pyright',
            \ ]

"let g:coc_global_extensions = [
" \ 'coc-tabnine',
" \ 'coc-explorer',
" \ 'coc-java',
" \ 'coc-translator',
" \ 'coc-git',
" \ 'coc-pairs',
" \ 'coc-markmap',
" \ 'coc-json',
" \ ]

nnoremap <silent> <leader>yv  :<C-u>CocList -A --normal yank<cr>
nnoremap <silent> <leader>yc  :CocCommand yank.clean<cr>
"coc-snippets
" Use <C-l> for trigger snippet expand.
imap <C-l> <Plug>(coc-snippets-expand)

" Use <C-j> for select text for visual placeholder of snippet.
" vmap <C-j> <Plug>(coc-snippets-select)

" Use <C-j> for both expand and jump (make expand higher priority.)
" imap <C-j> <Plug>(coc-snippets-expand-jump)

" Use <leader>x for convert visual selected code to snippet
xmap <leader><leader>x  <Plug>(coc-convert-snippet)

"coc-marketplace
nnoremap <silent> <leader>lm :CocList marketplace<cr>
"
"--------------------------------------------------------
" _   _ _       _     _     _       _     _             "
"| | | (_) __ _| |__ | |   (_) __ _| |__ | |_           "
"| |_| | |/ _` | '_ \| |   | |/ _` | '_ \| __|          "
"|  _  | | (_| | | | | |___| | (_| | | | | |_           "
"|_| |_|_|\__, |_| |_|_____|_|\__, |_| |_|\__|          "
"         |___/               |___/                     "
"--------------------------------------------------------
lua << EOF

-- 换源
-- for _, config in pairs(require("nvim-treesitter.parsers").get_parser_configs()) do
--     config.install_info.url = config.install_info.url:gsub("https://hub.fastgit.xyz/", "something else")
-- end

require'nvim-treesitter.configs'.setup {
ensure_installed = {'c', 'java', 'lua', 'python', 'vim' , 'json' ,'markdown', 'go', 'gomod'  },
highlight = {
enable = true,
}
}
require'nvim-treesitter.configs'.setup {
    incremental_selection = {
    enable = true,
    keymaps = {
        init_selection = "<SPACE>",
        node_incremental = "<SPACE>",
        scope_incremental = "<TAB>",
        node_decremental = "<BS>",
        },
    },
}
-- integrate with rainbow
require "nvim-treesitter.highlight"
local hlmap = vim.treesitter.highlighter.hl_map
hlmap.error = nil
hlmap["punctuation.delimiter"] = "Delimiter"
hlmap["punctuation.bracket"] = nil

EOF

